﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace OpenGameEngine.Logging
{
    public class FileLogProvider
        : ILogProvider
    {
        private StreamWriter logWriter;

        public LogImportance MinimumImportance { get; set; }

        public FileLogProvider(string file, LogImportance minimumImportance)
        {
            this.MinimumImportance = minimumImportance;
            logWriter = new StreamWriter(file, true);
        }

        public void Log(string log, LogImportance importance)
        {
            lock (logWriter)
            {
                if (importance >= MinimumImportance)
                    logWriter.WriteLine(log);
                logWriter.Flush();
            }
        }
    }
}
